package com.wksc.test.ehcache.util;

import java.io.Serializable;

/**
 * Created by panhongwei on 2015/5/23.
 */
public class BaseMessage implements Serializable {

    /**
     * success,error,warning
     */
    private String code;
    private String msg;
    private Object result;

    public enum CodeType{
        SUCCESS("success"),
        ERROR("error"),
        WARNING("warning");

       private String code;

        CodeType(String code) {
            this.code = code;
        }

        public String getCode() {
            return code;
        }
    }

    public BaseMessage(CodeType codeType, String msg) {
        this.code = codeType.getCode();
        this.msg = msg;
    }

    public BaseMessage(CodeType codeType, String msg, Object result) {
        this.code = codeType.getCode();
        this.msg = msg;
        this.result = result;
    }

    public static BaseMessage success(String msg,Object result){

        return new BaseMessage(CodeType.SUCCESS,msg,result);
    }

    public static BaseMessage error(String msg,Object result){

        return new BaseMessage(CodeType.ERROR,msg,result);
    }

    public static BaseMessage warning(String msg, Object result){

        return new BaseMessage(CodeType.WARNING,msg,result);
    }

    public static BaseMessage success(String msg ){

        return new BaseMessage(CodeType.SUCCESS,msg);
    }

    public static BaseMessage error(String msg){

        return new BaseMessage(CodeType.ERROR,msg);
    }

    public static BaseMessage warning(String msg){

        return new BaseMessage(CodeType.WARNING,msg);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }
}
